package cn.tradewin.advisor.pages.project.init;

import java.util.List;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import cn.tradewin.advisor.exceptions.DBException;
import cn.tradewin.advisor.persist.model.Customer;
import cn.tradewin.advisor.persist.services.CustomerService;

public class CustomerBoard {
	
	@Inject
	private Messages messages;
	
	@Inject
	private BeanModelSource beanModelSource;
	
	@Property
	private BeanModel<Customer> beanModel;
	
	@Inject
	private CustomerService customerService;
	
	@Property
	private List<Customer> customers;
	
	@Property
	private Customer customer;
	
	@SetupRender
	void setupRender() throws DBException {
		beanModel = beanModelSource.createDisplayModel(Customer.class, messages);
		beanModel.add("action", null);

		beanModel.include("sname", "name", "countryName","location");
		beanModel.get("name").sortable(false);
		beanModel.get("sname").sortable(false);
		beanModel.get("countryName").sortable(false);
		beanModel.get("location").sortable(false);
	}	
	
	@OnEvent(EventConstants.PREPARE_FOR_RENDER)
	void prepareForRender() {
		customers = customerService.listAllCustomers();
	}
}
